package com.acelance.activiti.demo.main;

import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;

/**
 * 功能描述：
 * <p>
 * description
 * </p>
 *
 * @author Lesso
 * @version 1.0.0
 * @see com.acelance.activiti.demo.main
 * @since 2020/6/3 21:54
 */
@Slf4j
public class DemoMain {
    public static void main(String[] args) {
        log.info("====================程序启动===================");
        // 创建流程引擎
        ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();
        ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
        String name = processEngine.getName();
        String version = ProcessEngine.VERSION;
        log.info("流程引擎版本名称【{}-{}】",name,version);
        // 部署定义流程文件
        RepositoryService repositoryService = processEngine.getRepositoryService();
        DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
        deploymentBuilder.addClasspathResource("secondary-process2.bpmn.xml");
        Deployment deployment = deploymentBuilder.deploy();
        String id = deployment.getId();
        System.out.println("=======================" + id);
        ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery().deploymentId("2502");
        ProcessDefinition processDefinition = processDefinitionQuery.singleResult();
        log.info("ProcessDefinition: {}",processDefinition);
        log.info(" 流程定义对象:【{}】-部署后的ID【{}】",processDefinition.getName(),processDefinition.getId());
        // 启动运行流程
        // 处理流程任务
        log.info("--------------------程序结束-------------------");
    }
}
